<template>
  <div class="app-container">
    <div class="card aside">
      <div class="card-title">项目过程管理</div>
      <el-divider />
      <ul class="card-content">
        <li
          v-for="(item, index) in menukArr"
          :key="item.name"
          :class="{ active: activeIdx === index }"
          @click="changeMenu(item, index)"
        >
          {{ item.name }}
        </li>
      </ul>
    </div>
    <el-row type="flex" class="content">
      <div class="card back">
        <el-button icon="el-icon-arrow-left" @click="back">返回</el-button>
        <div class="card-title">{{ projectInfo.name }}</div>
      </div>
      <div class="card main">
        <component :is="componentName"></component>
      </div>
    </el-row>
  </div>
</template>

<script>
export default {
  components: {
    processManagement: () => import("./components/processManagement"),
    fundRegistration: () => import("./components/fundRegistration"),
    expensesClaim: () => import("./components/expensesClaim"),
    projectChanges: () => import("./components/projectChanges"),
    progressReview: () => import("./components/progressReview"),
    changeApproval: () => import("./components/changeApproval"),
    reimbursementReview: () => import("./components/reimbursementReview"),
  },
  props: {
    projectInfo: {
      type: Object,
      default: () => ({}),
    },
  },
  provide() {
    return {
      projectId: this.projectInfo.id,
    };
  },
  data() {
    return {
      menukArr: [
        { name: "进度管理", key: "processManagement" },
        { name: "经费登记", key: "fundRegistration" },
        { name: "经费报销", key: "expensesClaim" },
        { name: "项目变更", key: "projectChanges" },
      ],
      activeIdx: 0,
      componentName: "processManagement",
    };
  },
  mounted() {
    // 科研管理员显示
    let loginUser = JSON.parse(sessionStorage.getItem("loginUserinfo")).name;
    if (loginUser == "科研管理员") {
      const obj = [
        { name: "进度审核", key: "progressReview" },
        { name: "报销审核", key: "reimbursementReview" },
        { name: "变更审核", key: "changeApproval" },
      ];
      this.menukArr.push(...obj);
    }
  },
  methods: {
    back() {
      this.$emit("change", { componentName: "projectList" });
    },
    changeMenu({ key }, idx) {
      this.activeIdx = idx;
      this.componentName = key;
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  height: 100%;
  display: flex;
  background-color: #f4f5fc;
  .card {
    padding: 12px 20px;
    border: 1px solid #dcdfe6;
    box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12), 0 0 6px 0 rgba(0, 0, 0, 0.04);
    background-color: #fff;
  }
  .card-title {
    font-size: 18px;
    line-height: 30px;
    font-weight: bold;
  }
  .card-content {
    list-style: none;
    margin: 0;
    padding: 0;
    line-height: 30px;
    font-size: 14px;
    color: #333;
    li {
      padding: 0 10px;
      cursor: pointer;
    }
    .active {
      color: #0b847b;
      background-color: #f0f7ff;
    }
  }
  .back {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    .card-title {
      margin: 0 auto;
    }
  }
  .aside {
    width: 180px;
    margin-right: 10px;
  }
  .content,
  .main {
    flex: 1;
    overflow: hidden;
  }
  .content {
    flex-direction: column;
  }
  .main {
    padding: 20px;
  }
}
.el-divider--horizontal {
  margin: 12px 0;
}
</style>
